{extend name="base/base" /}
{block name="main"}
<style>
.layui-form-pane .layui-form-label{width: 130px;}
.layui-form-pane .layui-input-block{
        margin-left: 130px;
}
</style>
<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/user-daoru')}">
   <div class="layui-form-item">
        <label class="layui-form-label">选择xlsx文件</label>
		<div class="layui-input-block">
			<input type="text" readonly=" "value="{:isset($list.img)?$list.img:''}" name="fileurl" id="fileUrl" lay-verify="uploadimg" class="layui-input" style="width:200px;display:inline">
			<button type="button" class="layui-btn layui-btn-primary fileBtn"><i class="layui-icon">&#xe67c;</i> 上传</button>
			<a target="_blank" style="color:red" href="/uploads/daoru/moban/会员导入模板.xlsx">《下载导入模板》</a>
		</div>
	</div>
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script>
    layui.config({
        base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'jquery', 'formSelects','upload'], function () {
        var formSelects = layui.formSelects, form = layui.form, $ = layui.jquery,upload = layui.upload;
        
        //上传文件
		upload.render({
			elem: '.fileBtn',
			url: "{:url('/admin/upload_excel')}",
			type:'file',
			accept:'file',
			exts: 'xlsx',
			multiple: false,
            auto: true,//是否自动上传，true自动上传,false手动上传

			done: function(data){
				var icon=5;
				if(!data.code){
					icon=6;
					$('#fileUrl').val(data.data.url);
				}
				layer.msg(data.msg, {icon:icon,time: 1500});
			},
			error: function(){
				layer.msg('上传失败', {icon:icon,time: 1500});
			}
		});
		
        formSelects.on('selectId', function (id, vals, val, isAdd, isDisabled) {
            $('#group_id').val(layui.formSelects.value(id, 'val'));
        }, true);
        //表单验证
        form.verify({
            
        });
        //表单提交
        form.on("submit(*)", function (data) {
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}